﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TEG.Models;

namespace TEG.Controllers
{ 
    public class VehiculoModelosController : Controller
    {
        private ArlandriaEntities db = new ArlandriaEntities();

        //
        // GET: /VehiculoModelos/

        public ViewResult Index()
        {
            var vehiculomodelo = db.VehiculoModelo.Include("VehiculoMarca");
            return View(vehiculomodelo.ToList());
        }

        //
        // GET: /VehiculoModelos/Details/5

        public ViewResult Details(int id)
        {
            VehiculoModelo vehiculomodelo = db.VehiculoModelo.Single(v => v.Id == id);
            return View(vehiculomodelo);
        }

        //
        // GET: /VehiculoModelos/Create

        public ActionResult Create()
        {
            ViewBag.IdVehiculoMarca = new SelectList(db.VehiculoMarca, "Id", "Nombre");
            return View();
        } 

        //
        // POST: /VehiculoModelos/Create

        [HttpPost]
        public ActionResult Create(VehiculoModelo vehiculomodelo)
        {
            if (ModelState.IsValid)
            {
                db.VehiculoModelo.AddObject(vehiculomodelo);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.IdVehiculoMarca = new SelectList(db.VehiculoMarca, "Id", "Nombre", vehiculomodelo.IdVehiculoMarca);
            return View(vehiculomodelo);
        }
        
        //
        // GET: /VehiculoModelos/Edit/5
 
        public ActionResult Edit(int id)
        {
            VehiculoModelo vehiculomodelo = db.VehiculoModelo.Single(v => v.Id == id);
            ViewBag.IdVehiculoMarca = new SelectList(db.VehiculoMarca, "Id", "Nombre", vehiculomodelo.IdVehiculoMarca);
            return View(vehiculomodelo);
        }

        //
        // POST: /VehiculoModelos/Edit/5

        [HttpPost]
        public ActionResult Edit(VehiculoModelo vehiculomodelo)
        {
            if (ModelState.IsValid)
            {
                db.VehiculoModelo.Attach(vehiculomodelo);
                db.ObjectStateManager.ChangeObjectState(vehiculomodelo, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.IdVehiculoMarca = new SelectList(db.VehiculoMarca, "Id", "Nombre", vehiculomodelo.IdVehiculoMarca);
            return View(vehiculomodelo);
        }

        //
        // GET: /VehiculoModelos/Delete/5
 
        public ActionResult Delete(int id)
        {
            VehiculoModelo vehiculomodelo = db.VehiculoModelo.Single(v => v.Id == id);
            return View(vehiculomodelo);
        }

        //
        // POST: /VehiculoModelos/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            VehiculoModelo vehiculomodelo = db.VehiculoModelo.Single(v => v.Id == id);
            db.VehiculoModelo.DeleteObject(vehiculomodelo);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}